package chapter06

object Test15_TraitOverlying {
  def main(args: Array[String]): Unit = {
    val student = new Student15
    student.increase() //knowledge increase 从后向前做的叠加

    //钻石问题特征叠加
    val ball = new MyFootBall
    println(ball.describe())
  }
}

trait Knowledge15 {
  var amount = 0

  def increase() = {
    amount += 1
    println("knowledge increase")
  }
}

//定义球类
trait Ball {
  def describe(): String = "ball"
}

//定义颜色特征
trait ColorBall extends Ball {
  var color: String = "red"

  override def describe(): String = color + "-" + super.describe()
}

//定义种类特征
trait CategoryBall extends Ball {
  var category: String = "foot"

  override def describe(): String = category + "-" + super.describe()
}

trait Func {
  def describe(): String = "function"
}

//定义一个自定义球的类
class MyFootBall extends CategoryBall with Func with ColorBall {
  // override def describe(): String ="my ball is "+ super.describe()
  override def describe(): String = "my ball is " + super[CategoryBall].describe()
}


trait Talent15 {
  def singing(): Unit

  def dancing(): Unit

  def increase(): Unit = println("talent increased")
}

//从右向左进行替代
class Student15 extends Person13 with Talent15 with Knowledge15 {
  override def singing(): Unit = println("singing")

  override def dancing(): Unit = println("dancing")

  override def increase(): Unit = super.increase()
}
